성격 유형 검사하기
Solution
function solution(survey, choices) {
const round = ["RT", "CF", "JM", "AN"];
const resultObj = { R: 0, T: 0, C: 0, F: 0, J: 0, M: 0, A: 0, N: 0 };
// 점수 누적
survey.forEach((question, idx) => {
const [no, yes] = question.split("");
const choice = choices[idx];
resultObj[4 < choice ? yes : no] += Math.abs(choice - 4);
});
// 성격 결정
return round.reduce(
(acc, [a, b]) => (resultObj[a] < resultObj[b] ? acc + b : acc + a),
""
);
}
Review
.